<?php
class DefaultController extends BaseController
{
    public function actionIndex()
    {
        $data = DailyUtility::getDashboard();
        $this->render('index', $data);
    }

    public function actionCCU()
    {
        $data = CCUUtility::getCCU();
        $this->render('ccu', $data);
    }

    public function actionExportDaily()
    {
        $out = DailyUtility::getCSV();
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Length: " . strlen($out));
        header("Content-type: text/x-csv");
        header("Content-Disposition: attachment; filename=daily.csv");
        echo $out;
    }

    public function actionDailyReport()
    {
        $date = DateUtility::yesterday();
        $data = array();
        $data['daily'] = DailyModel::getByDate($date);
        $data['daily_30'] = DailyModel::getByDate(DateUtility::ago($date, 30));
        $data['gifts'] = LogModel::getGiftAmount($date);
        $data['stickers'] = LogModel::getStickerAmount($date);
        $this->render('/mail/daily', $data);
    }

    public function actionMarketing()
    {
        $request = Yii::app()->request;
        $campaignId = Yii::app()->request->getParam('campaign');
        $email = Yii::app()->request->getParam('email');
        if($campaignId === null || $email === null)
        {
            return;
        }

        MarketingUtility::openEmail($campaignId, $email);
    }
}
